I have this list:
let teams = [
"real madrid",
"barcelona",
"milan",
"inter",
"juventus",
"manchester united",
"manchester city",
"liverpool",
"arsenal",
"chelsea",
"bayern munich",
];
I wrote code for choose random item from this list but I want display "-" as long as item length.
For example: choose real madrid ... I want this - - - - - - - - - - in the text box.
Use String.prototype.replace() with a small RegExp that will match any non-space character \S, and replace it with a hyphen - (PS: g stands for global replace)
const str = "Real Madrid";
const hyphenated = str.replace(/\S/g, "-");
console.log(hyphenated);
Happy hangman-ing!